// pages/main-self/index.js
import {
  getTopMV
} from "../../services/modules/video.js"
Page({
  data: {
    videoList: [],
    offset: 0,
    limit: 20,
    hasmore: true
  },
  async getList(limit, offset, isPull = false) {

    // 没有数据添加了就返回
    if (!this.data.hasmore) {
      // 停止上拉刷新
      wx.stopPullDownRefresh()
      return
    };
    const res = await getTopMV(offset, limit)
    // 停止上拉刷新
    wx.stopPullDownRefresh()
    if (!res.data) {
      this.setData({
        hasmore: false
      })
      return;
    }
    this.setData({
      videoList: isPull ? [...res.data, ...this.data.videoList, ] : [...this.data.videoList, ...res.data]
    })
  },
  onReachBottom() {
    this.setData({
      offset: this.data.offset + 20
    })
    this.getList(this.data.limit, this.data.offset)
  },

  onPullDownRefresh() {
    this.setData({
      offset: this.data.offset + 20
    })
    this.getList(this.data.limit, this.data.offset, true)
  },
  onLoad() {
    // 发送网络请求
    this.getList(this.data.limit, this.data.offset)
  }
})